<div class="fsh-rightPanel">
    <label> <input type="password" style="display: none"></label>
    <div class="layui-anim layui-anim-upbit">
        <div class="layui-form-item wx-search" id="list_form">
            <div class="layui-inline">
                <input type="text" name="course_task" placeholder="请输入作业标题" autocomplete="off" class="layui-input">
            </div>
            <button class="layui-btn btn-primary" id="search">搜索</button>
        </div>
        <table id="list_table" class="layui-hide" lay-filter="mainList"></table>
    </div>
</div>
<script>
    layui.use(['layer', 'form', 'table'], function () {
        var layer = layui.layer;
        var table = layui.table;
        var form = layui.form;
        var tableObj = table.render({
            elem: '#list_table'
            , url: context + '/api/educourse/getList?parent_id=-1&course_teacher_id=' + userInfo.user_id
            , request: {
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , align: 'center'
            , cols: [[ //表头
                {type: 'numbers', width: 80},
                {field: 'course_task', title: '任务名称', align: 'center'},
                {field: 'createDate', title: '任务时间', align: 'center'},
                {
                    title: '审核状态', align: 'center', width: 100, templet: function (d) {
                        switch (d.pass) {
                            case 0:
                                return "未提交";
                            case 1:
                                return "待审核";
                            case 2:
                                return "未通过";
                            default:
                                return "已通过";
                        }
                    }
                },
                {
                    title: '操作', width: 280, unresize: true, align: 'center',
                    templet: function (d) {
                        return '<a href="javascript:;" class="font-primary" lay-event="desc">任务查看</a>'
                            + '<a href="javascript:;" class="font-primary" lay-event="submit">提交审核</a>'
                    }
                }
            ]]
            , page: true
            , limit: 20 //每页默认显示的数量
        });

        // 检索
        $("#search").click(function () {
            reloadTable(tableObj);
        });

        //表格内部操作按钮监听
        table.on('tool(mainList)', function (obj) { //注：tool是工具条事件名，mainList是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            // 分配角色
            if (layEvent === 'desc') {
                showDialog({
                    title: '查看任务'
                    , template: 'desc'
                    , btn: ['确认']
                    , htmlData: data
                    , yes: function (index, layero) {
                        layer.close(index);
                    }

                })
            } else if (layEvent === 'submit') {
                showDialog({
                    title: '提交任务'
                    , template: 'submit'
                    , htmlData: data
                    , yes: function (index, layero) {
                        layui.form.on('submit(*)', function (data1) {
                            $.ajax({
                                url: context + '/api/educourse/updateOne',
                                type: 'PATCH',
                                dataType: 'json',
                                contentType: "application/json;charset-UTF-8",
                                data: JSON.stringify(data1.field),
                                success: function (result) {
                                    if (result.success) {
                                        $.ajax({
                                            url: context + '/api/educourse/submitAudit?id=' + data.course_id,
                                            type: 'PATCH',
                                            success: function (result) {
                                                if (result.success) {
                                                    layer.msg("已提交审核");
                                                    layer.close(index);
                                                    reloadTable(tableObj);
                                                } else {
                                                    layer.msg(result.msg);
                                                }
                                            },
                                            error: function () {
                                                layer.msg("提交失败");
                                            }
                                        });
                                    } else {
                                        layer.msg(result.msg);
                                    }
                                },
                                error: function () {
                                    layer.msg("上传失败");
                                }
                            })
                        });
                        layui.form.validate();
                    }

                })
            }
        });

    });
</script>
